package com.dp.util;

import com.alibaba.fastjson.JSONObject;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ESN
{
    private final static String [] hexDigits = {"H","T","X","W","I","N","A","C","M","E","O","U","R","S","Z","V"};

    /**正极加密（32位）*/
    public static String esn_32(String origin)
    {
        String result = null;

        try
        {
            result = batohs(MessageDigest.getInstance("MD5").digest(String.valueOf(origin).getBytes()));
        }
        catch(Exception e){}

        return result;
    }

    /**正极加密（16位）*/
    public static String esn_16(String origin)
    {
        String result = null;

        try
        {
            result = batohs(MessageDigest.getInstance("MD5").digest(String.valueOf(origin).getBytes())).substring(8, 24);
        }
        catch(Exception e){}

        return result;
    }

    /**MD5加密（32位）*/
    public static String md5_32(String origin)
    {
        String [] licencesn = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};
        String result = null;

        try
        {
            byte [] b = MessageDigest.getInstance("MD5").digest(String.valueOf(origin).getBytes());

            StringBuffer resultSb = new StringBuffer();

            for(int i = 0; i < b.length; i++)
            {
                int n = b[i];

                if(n < 0){n += 256;}

                int site1 = n / 16;
                int site2 = n % 16;

                resultSb.append(licencesn[site1] + licencesn[site2]);
            }

            result = resultSb.toString();
        }
        catch(Exception e){}

        return result;
    }

    /**MD5加密（16位）*/
    public static String md5_16(String origin)
    {
        String [] licencesn = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};
        String result = null;

        try
        {
            byte [] b = MessageDigest.getInstance("MD5").digest(String.valueOf(origin).getBytes());

            StringBuffer resultSb = new StringBuffer();

            for(int i = 0; i < b.length; i++)
            {
                int n = b[i];

                if(n < 0){n += 256;}

                int site1 = n / 16;
                int site2 = n % 16;

                resultSb.append(licencesn[site1] + licencesn[site2]);
            }

            result = resultSb.toString().substring(8, 24);
        }
        catch(Exception e){}

        return result;
    }

    /**初始认证，然后再转换为MDX密号（32位）（解决不同平台密号不一致的问题）。*/
    public static String mdx_32(String origin)
    {
        String [] licencesn = {"2", "8", "0", "3", "9", "6","4","7","1","5","A","C","M","W","P","Q"};
        String result = null;

        try
        {
            byte [] b = MessageDigest.getInstance("MD5").digest(String.valueOf(origin).getBytes());

            StringBuffer resultSb = new StringBuffer();

            for(int i = 0; i < b.length; i++)
            {
                int n = b[i];

                if(n < 0){n += 256;}

                int site1 = n / 16;
                int site2 = n % 16;

                resultSb.append(licencesn[site1] + licencesn[site2]);
            }

            result = resultSb.toString();
        }
        catch(Exception e){}

        return result;
    }

    /**初始认证，然后再转换为MDX密号（16位）（解决不同平台密号不一致的问题）。*/
    public static String mdx_16(String origin)
    {
        String [] licencesn = {"2", "8", "0", "3", "9", "6","4","7","1","5","A","C","M","W","P","Q"};
        String result = null;

        try
        {
            byte [] b = MessageDigest.getInstance("MD5").digest(String.valueOf(origin).getBytes());

            StringBuffer resultSb = new StringBuffer();

            for(int i = 0; i < b.length; i++)
            {
                int n = b[i];

                if(n < 0){n += 256;}

                int site1 = n / 16;
                int site2 = n % 16;

                resultSb.append(licencesn[site1] + licencesn[site2]);
            }

            result = resultSb.toString().substring(8, 24);
        }
        catch(Exception e){}

        return result;
    }

    private static String batohs(byte [] ba)
    {
        StringBuffer resultSb = new StringBuffer();

        for(int i = 0; i < ba.length; i++)
        {
            resultSb.append(btohs(ba[i]));
        }

        return resultSb.toString();
    }

    private static String btohs(byte b)
    {
        int n = b;

        if(n < 0){n += 256;}

        int site1 = n / 16;
        int site2 = n % 16;

        return hexDigits[site1] + hexDigits[site2];
    }

    /**任何时空下都不会重复的长度为32位的字串。*/
    public static String makesn()
    {
        String rdm1 = String.valueOf(Math.random());
        String rdm2 = String.valueOf(Math.random());
        String nano = String.valueOf(System.nanoTime());
        String hash = String.valueOf(new Object().toString().hashCode());
        String uuid = UUID.randomUUID().toString();

        return ESN.esn_32(rdm1 + rdm2 + nano + hash + uuid);
    }
   


    /**AES================================================================================*/

    private final static String ksn = "HTXWINACMEOURSZV";

    /**加密*/
    public static String enc_aes(String src)
    {
        if(ksn == null || ksn.length() != 16){return null;}

        try
        {
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(ksn.getBytes("UTF8"), "AES"));

            return byte2hex(cipher.doFinal(src.getBytes()));
        }
        catch(Exception e)
        {
            return null;
        }
    }

    /**解密*/
    public static String dec_aes(String enc)
    {
        if(ksn == null || ksn.length() != 16){return null;}

        try
        {
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(ksn.getBytes("UTF8"), "AES"));

            return new String(cipher.doFinal(hex2byte(enc)));
        }
        catch(Exception e)
        {
            return null;
        }
    }

    private static byte [] hex2byte(String strhex)
    {
        if(strhex == null) {return null;}

        int l = strhex.length();

        if(l % 2 == 1) {return null;}

        byte [] b = new byte[l / 2];

        for(int i = 0; i != l / 2; i++)
        {
            b[i] = (byte)Integer.parseInt(strhex.substring(i * 2, i * 2 + 2), 16);
        }

        return b;
    }

    private static String byte2hex(byte [] b)
    {
        String hs = "";

        for(int n = 0; n < b.length; n++)
        {
            String stmp = (Integer.toHexString(b[n] & 0XFF));

            hs = stmp.length() == 1 ? (hs + "0" + stmp) : (hs + stmp);
        }

        return hs.toUpperCase();
    }
    
    
    private static char[] base64EncodeChars = new char[] { 'A', 'B', 'C', 'D',  
            'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',  
            'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',  
            'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',  
            'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',  
            '4', '5', '6', '7', '8', '9', '+', '/', };  
    
    private static byte[] base64DecodeChars = new byte[] { -1, -1, -1, -1, -1,  
            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  
            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  
            -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59,  
            60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,  
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1,  
            -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,  
            38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1,  
            -1, -1 };
    
    /** 
     * 解密 
     * @param str 
     * @return 
     */  
    public static byte[] decode(String str) {  
        byte[] data = str.getBytes();  
        int len = data.length;  
        ByteArrayOutputStream buf = new ByteArrayOutputStream(len);  
        int i = 0;  
        int b1, b2, b3, b4;  
      
        while (i < len) {  
            do {  
                b1 = base64DecodeChars[data[i++]];  
            } while (i < len && b1 == -1);  
            if (b1 == -1) {  
                break;  
            }  
      
            do {  
                b2 = base64DecodeChars[data[i++]];  
            } while (i < len && b2 == -1);  
            if (b2 == -1) {  
                break;  
            }  
            buf.write((int) ((b1 << 2) | ((b2 & 0x30) >>> 4)));  
      
            do {  
                b3 = data[i++];  
                if (b3 == 61) {  
                    return buf.toByteArray();  
                }  
                b3 = base64DecodeChars[b3];  
            } while (i < len && b3 == -1);  
            if (b3 == -1) {  
                break;  
            }  
            buf.write((int) (((b2 & 0x0f) << 4) | ((b3 & 0x3c) >>> 2)));  
      
            do {  
                b4 = data[i++];  
                if (b4 == 61) {  
                    return buf.toByteArray();  
                }  
                b4 = base64DecodeChars[b4];  
            } while (i < len && b4 == -1);  
            if (b4 == -1) {  
                break;  
            }  
            buf.write((int) (((b3 & 0x03) << 6) | b4));  
        }  
        return buf.toByteArray();  
    }

    /**
     * UUID加密
     * */
    public static String getUUID() {
        return UUID.randomUUID().toString();
//        return UUID.randomUUID().toString().replaceAll("-", "");
    }





    public static String getUUID36(){
        String uuid36 = UUID.randomUUID().toString();
        return uuid36;
    }

    /**
     * 校验邮箱
     * */
    public static boolean checkEmail(String email) {
        boolean flag = false;
        try {
            String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
            Pattern regex = Pattern.compile(check);
            Matcher matcher = regex.matcher(email);
            flag = matcher.matches();
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }

    /**
     * 校验手机号
     * */
    public static boolean checkMobileNumber(String mobileNumber) {
        boolean flag = false;
        try {
            Pattern regex = Pattern.compile("^(((13[0-9])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8})|(0\\d{2}-\\d{8})|(0\\d{3}-\\d{7})$");
            Matcher matcher = regex.matcher(mobileNumber);
            flag = matcher.matches();
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }

    /**
     * 8位随机密码
     * */
    public static String genRandomNum(){
        int  maxNum = 36;
        int i;
        int count = 0;
        char[] str = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
                'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
                'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
        StringBuffer pwd = new StringBuffer("");
        Random r = new Random();
        while(count < 8){
            i = Math.abs(r.nextInt(maxNum));
            if (i >= 0 && i < str.length) {
                pwd.append(str[i]);
                count ++;
            }
        }
        return pwd.toString();
    }

    public static List<String> dateToDate(String date1,String date2){
        int y1 = Integer.parseInt(date1.substring(0,4));
        int m1 = Integer.parseInt(date1.substring(5,7));
        int d1 = Integer.parseInt(date1.substring(8,10));
        int y2 = Integer.parseInt(date2.substring(0,4));
        int m2 = Integer.parseInt(date2.substring(5,7));
        int d2 = Integer.parseInt(date2.substring(8,10));

        List<String> ylist = new ArrayList<String>();
        //判断年份大于1
        if(y2 - y1 > 1){
            //多年
            for(int i=y1;i <= y2;i++ ){
                ylist.add(i+"");
            }
        }else if (y2 - y1 == 1){
            //两个日期跨年了
            //判断跨年时间月份是否正好12个月
            if((12-m1)+m2 > 12 ){
                ylist.add(y1+"");
                ylist.add(y2+"");
            }else if((12-m1)+m2 <= 12){
                if(m1 - m2 == 11 && (31-d1+1)+d2 <=31 ){
                    for(int i=d1;i<=31;i++){
                        String flag = "-0";
                        if(i < 10){
                            flag = flag + i;
                            ylist.add(y1+"-"+date1.substring(5,7)+flag);
                        }else{
                            ylist.add(y1+"-"+date1.substring(5,7)+"-"+i);
                        }
                    }
                    for(int j=1;j<=d2;j++){
                        String flag = "-0";
                        if(j < 10){
                            flag = flag + j;
                            ylist.add(y2+"-"+date2.substring(5,7)+flag);
                        }else{
                            ylist.add(y2+"-"+date2.substring(5,7)+"-"+j);
                        }
                    }
                }else{
                    for(int i=m1;i <= 12;i++ ){
                        String flag = "-0";
                        if(i < 10){
                            flag = flag + i;
                            ylist.add(y1+flag);
                        }else{
                            ylist.add(y1+"-"+i);
                        }
                    }
                    for(int j=1;j <= m2;j++ ){
                        String flag = "-0";
                        if(j < 10){
                            flag = flag + j;
                            ylist.add(y2+flag);
                        }else{
                            ylist.add(y2+"-"+j);
                        }
                    }
                }
            }
        }else{
            //两个日期在同一年范围内
            if(m2-m1>1){
                for(int k=m1;k<=m2;k++){
                    String flag = "-0";
                    if(k < 10){
                        flag = flag + k;
                        ylist.add(y2+flag);
                    }else{
                        ylist.add(y2+"-"+k);
                    }
                }
            }else{
                if(m1 == m2){
                    for(int i=d1;i<=d2;i++){
                        String flag = "-0";
                        if(i < 10){
                            flag = flag + i;
                            ylist.add(y1+"-"+date1.substring(5,7)+flag);
                        }else{
                            ylist.add(y1+"-"+date1.substring(5,7)+"-"+i);
                        }
                    }
                }else{
                    int m_dnum1 = mons(y1,m1);
                    if((m_dnum1-d1+1)+d2 <= 30){
                        for(int i=d1;i<=m_dnum1;i++){
                            String flag = "-0";
                            if(i < 10){
                                flag = flag + i;
                                ylist.add(y1+"-"+date1.substring(5,7)+flag);
                            }else{
                                ylist.add(y1+"-"+date1.substring(5,7)+"-"+i);
                            }
                        }
                        for(int j=1;j<=d2;j++){
                            String flag = "-0";
                            if(j < 10){
                                flag = flag + j;
                                ylist.add(y2+"-"+date2.substring(5,7)+flag);
                            }else{
                                ylist.add(y2+"-"+date2.substring(5,7)+"-"+j);
                            }
                        }
                    }else{
                        for(int k=m1;k<=m2;k++){
                            String flag = "-0";
                            if(k < 10){
                                flag = flag + k;
                                ylist.add(y2+flag);
                            }else{
                                ylist.add(y2+"-"+k);
                            }
                        }
                    }
                }
            }
        }
        return ylist;
    }

    public static int mons(int y,int m){
        int daynum = 0;
        switch (m){
            case 1 :
                daynum = 31;
                break;
            case 2 :
                if(y%4 > 0){
                    daynum = 28;
                }else{
                    daynum = 29;
                }
                break;
            case 3 :
                daynum = 31;
                break;
            case 4 :
                daynum = 30;
                break;
            case 5 :
                daynum = 31;
                break;
            case 6 :
                daynum = 30;
                break;
            case 7 :
                daynum = 31;
                break;
            case 8 :
                daynum = 31;
                break;
            case 9 :
                daynum = 30;
                break;
            case 10 :
                daynum = 31;
                break;
            case 11 :
                daynum = 30;
                break;
            case 12 :
                daynum = 31;
                break;
        }
        return daynum;
    }

    /**
     * 计算当前天的前一周、前一个月、前三个月、前一年
     * */
    public static Map<String,Object> timeCount(String datetype){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String newtime =  format.format(new Date());
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        if("1".equals(datetype)){
            c.add(Calendar.DATE, - 7);
        }else if("2".equals(datetype)){
            c.add(Calendar.MONTH, -1);
        }else if("3".equals(datetype)){
            c.add(Calendar.MONTH, -3);
        }else if("4".equals(datetype)){
            c.add(Calendar.YEAR, -1);
        }
        Date m = c.getTime();
        String oldtime = format.format(m);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("newtime",newtime);
        map.put("oldtime",oldtime);
        return map;
    }

    //当前时间的前一天
    public static String beforeDay(){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date=new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        date = calendar.getTime();
        return sdf.format(date);
    }


    /**
     * AES模式下的CBC加密，解密
     */
    //解密密钥(自行随机生成)
    public static final String KEY = "yjikscb456m956dm";//密钥key
    public static final String IV  = "1ci5crnda6ojzgtr";//向量iv

    //认证密钥(自行随机生成)
    public static final String AK = "s2ip9g3y3bjr5zz7ws6kjgx3ysr82zzw";//AccessKey
    public static final String SK = "uv8zr0uen7aim8m7umcuooqzdv8cbvtf";//SecretKey

    //加密
    public static String Encrypt(String content) throws Exception {
        byte[] raw = KEY.getBytes("utf-8");
        SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");//"算法/模式/补码方式"
        //使用CBC模式，需要一个向量iv，可增加加密算法的强度
        IvParameterSpec ips = new IvParameterSpec(IV.getBytes());
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ips);
        byte[] encrypted = cipher.doFinal(content.getBytes());
        return new BASE64Encoder().encode(encrypted);
    }

    //解密
    public static String Decrypt(String content) throws Exception {
        try {
            byte[] raw = KEY.getBytes("utf-8");
            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            IvParameterSpec ips = new IvParameterSpec(IV.getBytes());
            cipher.init(Cipher.DECRYPT_MODE, skeySpec, ips);
            byte[] encrypted1 = new BASE64Decoder().decodeBuffer(content);
            try {
                byte[] original = cipher.doFinal(encrypted1);
                String originalString = new String(original);
                return originalString;
            } catch (Exception e) {
                System.out.println(e.toString());
                return null;
            }
        } catch (Exception ex) {
            System.out.println(ex.toString());
            return null;
        }
    }

    //获取认证签名(身份认证需要)
    public static String getSign(String currentTime) throws Exception {
        String sign = "";
        Map<String, Object> map=new HashMap<String,Object>();
        map.put("ak",AK);
        map.put("sk",SK);
        map.put("ts",currentTime);
        //获取 参数字典排序后字符串
        String decrypt = getOrderMap(map);
        try {
            //指定sha1算法
            MessageDigest digest = MessageDigest.getInstance("SHA-1");
            digest.update(decrypt.getBytes());
            //获取字节数组
            byte messageDigest[] = digest.digest();
            // Create Hex String
            StringBuffer hexString = new StringBuffer();
            // 字节数组转换为十六进制数
            for (int i = 0; i < messageDigest.length; i++) {
                String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
                if (shaHex.length() < 2) {
                    hexString.append(0);
                }
                hexString.append(shaHex);
            }
            sign = hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return sign;
    }

    //获取参数的字典排序
    private static String getOrderMap(Map<String,Object> maps){
        List<String> paramNames = new ArrayList<String>();
        for(Map.Entry<String,Object> entry : maps.entrySet()){
            paramNames.add(entry.getValue().toString());
        }
        Collections.sort(paramNames);
        StringBuilder paramStr = new StringBuilder();
        for(String paramName : paramNames){
            paramStr.append(paramName);
        }
        return paramStr.toString();
    }

    //===============================================start==================================================
    //使用AES-128-CBC加密模式，key需要为16位,key和iv可以相同！
    private static String KEYX = "1234567890123456";
    private static String IVX = "1234567890123456";
    /**
     * 加密方法
     * @param data  要加密的数据
     * @param key 加密key
     * @param iv 加密iv
     * @return 加密的结果
     * @throws Exception
     */
    public static String encryptX(String data, String key, String iv) throws Exception {
        try {

            Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");//"算法/模式/补码方式"NoPadding PkcsPadding
            int blockSize = cipher.getBlockSize();

            byte[] dataBytes = data.getBytes();
            int plaintextLength = dataBytes.length;
            if (plaintextLength % blockSize != 0) {
                plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize));
            }

            byte[] plaintext = new byte[plaintextLength];
            System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);

            SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
            IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());

            cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
            byte[] encrypted = cipher.doFinal(plaintext);

            return new BASE64Encoder().encode(encrypted);

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 解密方法
     * @param data 要解密的数据
     * @param key  解密key
     * @param iv 解密iv
     * @return 解密的结果
     * @throws Exception
     */
    public static String desEncryptX(String data, String key, String iv) throws Exception {
        try {
            byte[] encrypted1 =new BASE64Decoder().decodeBuffer(data);

            Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
            byte[] raw = key.getBytes("utf-8");
            SecretKeySpec keyspec = new SecretKeySpec(raw, "AES");
            IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());

            cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);

            byte[] original = cipher.doFinal(encrypted1);
            String originalString = new String(original);
            return originalString;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 使用默认的key和iv加密
     * @param data
     * @return
     * @throws Exception
     */
    public static String encryptX(String data) throws Exception {
        return encryptX(data, KEYX, IVX);
    }

    /**
     * 使用默认的key和iv解密
     * @param data
     * @return
     * @throws Exception
     */
    public static String desEncryptX(String data) throws Exception {
        return desEncryptX(data, KEYX, IVX);
    }
    //===============================================end==================================================
    //解密后数据恢复
    public static Map<String, Object> newMap(Map<String, Object> map) throws Exception {
        String str = (String) map.get("SXYGSJ");
        String EJM = ESN.desEncryptX(str);
        Map<String,Object> mmp = JSONObject.parseObject(EJM);
        return mmp;
    }



    public static void main(String[] args) throws Exception {
    	System.out.println(dec_aes("DE81711E4DF7E3557D644C1FC7084F87"));
        String content = "qwe123456";
        //加密
        String ens = ESN.Encrypt(content);
        System.out.println("加密后：" + ens);
//        //解密
        String des = ESN.Decrypt(ens);
        System.out.println("解密后：" + des);
        System.out.println(getUUID());




    }

    public static String createToken(String minecode) throws Exception {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String str="{mineCode="+minecode+",time="+df.format(new Date())+"}";
          ESN.Encrypt(str);




        return ESN.Encrypt(str);
    }
}